/*-------------------------------------------------------------------------
 *
 * pg_conversion.h
 *	  "转换" 系统目录 (pg_conversion) 的定义
 *
 * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
 * Portions Copyright (c) 1994, Regents of the University of California
 *
 * src/include/catalog/pg_conversion.h
 *
 * NOTES
 *	  Catalog.pm 模块读取此文件并推导模式
 *	  信息。
 *
 *-------------------------------------------------------------------------
 */
#ifndef PG_CONVERSION_H
#define PG_CONVERSION_H

#include "catalog/genbki.h"
#include "catalog/objectaddress.h"
#include "catalog/pg_conversion_d.h"

/* ----------------
 *		pg_conversion 定义。cpp 将其转换为 
 *		typedef struct FormData_pg_conversion
 * ----------------
 */
CATALOG(pg_conversion,2607,ConversionRelationId)
{
	/* oid */
	Oid			oid;

	/* 转换的名称 */
	NameData	conname;

	/* 转换所属的命名空间 */
	Oid			connamespace BKI_DEFAULT(pg_catalog) BKI_LOOKUP(pg_namespace);

	/* 转换的所有者 */
	Oid			conowner BKI_DEFAULT(POSTGRES) BKI_LOOKUP(pg_authid);

	/* FOR 编码 id */
	int32		conforencoding BKI_LOOKUP(encoding);

	/* TO 编码 id */
	int32		contoencoding BKI_LOOKUP(encoding);

	/* 转换过程的 OID */
	regproc		conproc BKI_LOOKUP(pg_proc);

	/* 如果这是默认转换，则为真 */
	bool		condefault BKI_DEFAULT(t);
} FormData_pg_conversion;

/* ----------------
 *		Form_pg_conversion 对应指向具有 pg_conversion 关系格式的元组的指针。
 * ----------------
 */
typedef FormData_pg_conversion *Form_pg_conversion;

DECLARE_UNIQUE_INDEX(pg_conversion_default_index, 2668, ConversionDefaultIndexId, on pg_conversion using btree(connamespace oid_ops, conforencoding int4_ops, contoencoding int4_ops, oid oid_ops));
DECLARE_UNIQUE_INDEX(pg_conversion_name_nsp_index, 2669, ConversionNameNspIndexId, on pg_conversion using btree(conname name_ops, connamespace oid_ops));
DECLARE_UNIQUE_INDEX_PKEY(pg_conversion_oid_index, 2670, ConversionOidIndexId, on pg_conversion using btree(oid oid_ops));


extern ObjectAddress ConversionCreate(const char *conname, Oid connamespace,
									  Oid conowner,
									  int32 conforencoding, int32 contoencoding,
									  Oid conproc, bool def);
extern Oid	FindDefaultConversion(Oid connamespace, int32 for_encoding,
								  int32 to_encoding);

#endif							/* PG_CONVERSION_H */
